import { http } from "@/utils/http";

// 库存基本信息接口
export interface InventorySummaryItem {
  id: number;
  materialId: number;
  price: number;
  stocks: number;
  updateTime: string;
  createTime: string;
  tenantId: number;
  // 扩展字段
  materialName?: string;
  brand?: string;
  specification?: string;
  unit?: string;
}

// 查询库存列表参数
export interface InventorySummaryListParams {
  page?: number;
  limit?: number;
  brand?: string;
  specification?: string;
  name?: string;
}

// 查询库存列表返回结果
export interface InventorySummaryListResult {
  code: number;
  data?: {
    records?: InventorySummaryItem[];
    totalRow?: number;
  };
  message: string;
}

// 更新库存参数
export interface InventorySummaryUpdatePayload {
  id: number;
  materialId: number;
  price: number;
  stocks: number;
  updateTime: string;
  createTime: string;
  tenantId: number;
}

// 更新库存返回结果
export interface InventorySummaryUpdateResult {
  code: number;
  data?: object;
  message: string;
}

// 查询单个库存返回结果
export interface InventorySummaryDetailResult {
  code: number;
  data?: InventorySummaryItem;
  message: string;
}

// 删除库存返回结果
export interface InventorySummaryDeleteResult {
  code: number;
  data?: object;
  message: string;
}

// 查询所有库存返回结果
export interface InventorySummaryAllListResult {
  code: number;
  data?: object;
  message: string;
}

/**
 * 修改库存信息
 * @param data 库存信息
 * @returns 修改结果
 */
export const updateInventorySummary = (data: InventorySummaryUpdatePayload) => {
  return http.request<InventorySummaryUpdateResult>("post", "inventorySummary/update", { data });
};

/**
 * 查询库存列表
 * @param data 查询参数
 * @returns 库存列表数据
 */
export const getInventorySummaryList = (data: InventorySummaryListParams) => {
  return http.request<InventorySummaryListResult>("post", "inventorySummary/list", { data });
};

/**
 * 根据ID查询库存信息
 * @param id 库存ID
 * @returns 库存详细信息
 */
export const getInventorySummaryById = (id: number) => {
  return http.request<InventorySummaryDetailResult>("get", "inventorySummary/find", { params: { id } });
};

/**
 * 删除库存信息
 * @param id 库存ID
 * @returns 删除结果
 */
export const deleteInventorySummary = (id: number) => {
  return http.request<InventorySummaryDeleteResult>("get", "inventorySummary/delete", { params: { id } });
};

/**
 * 查询所有库存信息
 * @returns 所有库存数据
 */
export const getAllInventorySummary = () => {
  return http.request<InventorySummaryAllListResult>("get", "inventorySummary/findAll");
};